fn main() {
    // Creating a New String
    let mut s = String::new();

    let data = "initial contents";
    let s = data.to_string();

    // The method also works on a literal directly:
    let s = "initial contents".to_string();

    let s = String::from("initial contents");

    // let hello = String::from("السلام عليكم");
    // let hello = String::from("Dobrý den");
    // let hello = String::from("Hello");
    // let hello = String::from("שלום");
    // let hello = String::from("नमस्ते");
    // let hello = String::from("こんにちは");
    // let hello = String::from("안녕하세요");
    // let hello = String::from("你好");
    // let hello = String::from("Olá");
    // let hello = String::from("Здравствуйте");
    // let hello = String::from("Hola");

    // Updating a String
    let mut s = String::from("foo");
    s.push_str("bar");
    println!("s: {s}");

    let mut s1 = String::from("foo");
    let s2 = "bar";
    s1.push_str(s2);
    println!("s1 is {s1} s2 is {s2}");

    let mut s = String::from("lo");
    s.push('l');
    println!("s is {s}");

    let s1 = String::from("Hello, ");
    let s2 = String::from("world!");
    let s3 = s1 + &s2; // note s1 has been moved here and can no longer be used
    println!("s3 is {s3}");

    let s1 = String::from("tic");
    let s2 = String::from("tac");
    let s3 = String::from("toe");

    let s = s1 + "-" + &s2 + "-" + &s3;
    println!("s is {s}");
    let s4 = String::from("tic");
    let s5 = String::from("tac");
    let s6 = String::from("toe");
    let s = format!("{s4}-{s5}-{s6}");
    println!("s is {s}");

    // Indexing into Strings
    // Note: Strings can not support indexing

    // Slicing Strings
    let hello = "Здравствуйте";
    let s = &hello[0..4];

    // Methods for Iterating Over Strings
    for c in "Зд".chars() {
        println!("{c}");
    }

    for b in "Зд".bytes() {
        println!("{b}");
    }

    let s1 = String::from("hello,world");
    let s2 = String::from("hello");

    if s1.contains(&s2) {
        println!("s1 contains s2");
    }else {
        println!("s1 not contains s2");
    }

    let s3 = s1.replace("world","jimi");
    println!("s3 is {s3}");

    // exercices
    // Convert strings to pig latin. The first consonant of each word is moved to the end of the word and ay is added,
    // so first becomes irst-fay. Words that start with a vowel have hay added to the end instead (apple becomes apple-hay). Keep in mind the details about UTF-8 encoding!

    let mut words : Vec<String> = vec![String::from("apple"),String::from("first"),String::from("people"),String::from("iir"),String::from("uklili"),String::from("test")];

    for mut word in words {
        print!("{} ->", word);
        handleLatin(&mut word);
        println!("{word}");
    }
}

fn handleLatin(word : &mut String){
    if word.starts_with("a") || word.starts_with("e") || word.starts_with("i")
    || word.starts_with("o") || word.starts_with("u") {
        word.push_str("-hay");
    }else{
        let cha = word.chars().next().unwrap();
        let len = word.len();
        let mut s: String = (&word[1..len]).to_string();
        *word = s + "-";
        word.push(cha);
        word.push_str("ay");
    }
}